package edu.scau.pro.hotel.controller;

import edu.scau.pro.hotel.entity.HotelDateDiscount;
import edu.scau.pro.hotel.service.IHotelDateDiscountService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
 * (HotelDateDiscount)表控制层
 *
 * @author CJW
 * @since 2022-04-24 13:17:01
 */
@RestController
@RequestMapping("hotelDateDiscount")
public class HotelDateDiscountController {
    /**
     * 服务对象
     */
    @Autowired
    private IHotelDateDiscountService hotelDateDiscountService;

    /**
     * 分页查询
     *
     * @param hotelDateDiscount 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<HotelDateDiscount>> queryAll(HotelDateDiscount hotelDateDiscount) {
        return ResponseEntity.ok(this.hotelDateDiscountService.queryAll(hotelDateDiscount));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<HotelDateDiscount> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.hotelDateDiscountService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param hotelDateDiscount 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<HotelDateDiscount> add(@RequestBody HotelDateDiscount hotelDateDiscount) {
        return ResponseEntity.ok(this.hotelDateDiscountService.insert(hotelDateDiscount));
    }

    /**
     * 编辑数据
     *
     * @param hotelDateDiscount 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<HotelDateDiscount> edit(@RequestBody HotelDateDiscount hotelDateDiscount) {
        return ResponseEntity.ok(this.hotelDateDiscountService.update(hotelDateDiscount));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.hotelDateDiscountService.deleteById(id));
    }

    @GetMapping("/page")
    public PageInfo page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, HotelDateDiscount hotelDateDiscount) {
        PageHelper.startPage(pageNum,pageSize);
        List<HotelDateDiscount> list = this.hotelDateDiscountService.queryAll(hotelDateDiscount);
        PageInfo<List> pageInfo = new PageInfo(list);
        return pageInfo;
    }
}
